1. Field of the Invention
The present invention relates to a device and a method for information processing, and a program, and particularly to a device and a method for information processing, and a program that can properly recognize a two-dimensional bar code.
2. Description of the Related Art
FIG. 1 shows an example of a two-dimensional bar code (hereinafter referred to as a 2D code) 101 recognized by a personal computer or the like, for example. By making the personal computer recognize the 2D code 101, it is possible to make the personal computer perform a process corresponding to predetermined information coded by the 2D code 101.
The 2D code 101 includes a guide part 111 and a code part 112 provided within an area of a rectangle having a length of 7 squares (hereinafter referred to as blocks) in an X-axis direction and a length of 9.5 blocks in a Y-axis direction.
The guide part 111 is formed by a rectangular cell having a length of 7 blocks in the X-axis direction and a length of 1.5 blocks in the Y-axis direction.
The code part 112 is provided one block away from the guide part 111. The code part 112 has square cells arranged in a two-dimensional pattern.
As shown in FIG. 2, the cells forming the code part 112 include an upper left corner cell 121-1 situated seven blocks away from a left end of the guide part 111 in an upward direction in the figure, an upper right corner cell 121-2 situated seven blocks away from a right end of the guide part 111 in the upward direction, a lower left corner cell 121-3 situated one block away from the left end of the guide part 111 in the upward direction, and a lower right corner cell 121-4 situated one block away from the right end of the guide part 111 in the upward direction. Incidentally, when the upper left corner cell 121-1, the upper right corner cell 121-2, the lower left corner cell 121-3, and the lower right corner cell 121-4 do not particularly need to be differentiated from each other, these corner cells will be referred to collectively as corner cells 121.
No cells are present in an area of three adjacent blocks (blocks represented by dotted lines in FIG. 2) around the corner cells 121.
Cells (hereinafter referred to as coded cells as appropriate) 122 other than the corner cells 121 in the code part 112 are arranged two-dimensionally according to predetermined alphanumeric characters and the like.
A personal computer detects the guide part 111 and the corner cells 121 in the code part 112 from an image of the 2D code 101, identifies an area where the code part 112 is present on the basis of the guide part 111 and the corner cells 121, and then obtains coded information from the arrangement pattern of the coded cells 122 present in the area.
A 2D code recognizing process in the past will next be described with reference to a flowchart of FIG. 3 (see Japanese Patent Laid-Open No. 2000-148904).
In step S1, the value of a counter i counting the setting of a threshold value representing a predetermined luminance value is initialized to one. In this example, as shown in FIG. 4, the threshold value is set in five steps. The magnitude of the threshold value is decreased stepwise from a threshold value A indicated at setting number 1, the threshold value A being the highest threshold value, to a threshold value E indicated at setting number 5.
Returning to FIG. 3, in step S2, image data of a 2D code 101 captured by a personal computer is subjected to a binarizing process on the basis of a threshold value of a setting number corresponding to the value of the counter i.
A pixel retaining a luminance value higher than the threshold value is coded into “1,” and the pixel is made white on display. A pixel thus coded into “1” will hereinafter be referred to as a white pixel.
A pixel retaining a luminance value equal to or lower than the threshold value is coded into “0,” and the pixel is made black on display. A pixel thus coded into “0” will hereinafter be referred to as a black pixel.
In next step S3, as shown in FIG. 5, numbers are set to areas where black pixels are connected to each other (hereinafter referred to as black pixel connected areas) (the areas are labeled) in order from an upper left to a lower right with an area where black pixels are connected to each other as one area.
In step S4, a total number M of black pixel connected areas labeled in step S3 is determined, and then whether the obtained total number M of black pixel connected areas is 257 or larger is determined. When M is 257 or larger, it is determined that the binarized image is not an appropriate image for a subsequent process. The process proceeds to step S5.
In step S5, whether the value of the counter i is equal to a number N (=5) of set threshold values (i=5) is determined. When the value of the counter i is not equal to five, the value of the counter i is incremented by one in step S6. The process returns to step S2. In step S2, the captured image data is subjected to the binarizing process again on the basis of a threshold value of a setting number corresponding to the value of the counter i incremented by one.
As described above, the threshold value A indicated at setting number 1 is the highest threshold value. When the binarizing process is performed on the basis of the threshold value A, luminance values of many pixels of the image data is lower than the threshold value A, and therefore many pixels are made to be black pixels, thus resulting in a large total number M of black pixel connected areas. Accordingly, when a result of the determination in step S4 is YES, the value of the counter i is incremented by one in step S5. Thus performing the binarizing process on the basis of a threshold value lower by one step can reduce the number of pixels made to be black pixels, that is, black pixel connected areas.
When it is determined in step S5 that i=5, that is, when an appropriate total number M of black pixel connected areas are not generated on the basis of any of the threshold values A to E, it is determined that the image data for one frame does not include an image of a 2D code 101. Then the process is ended.
When it is determined in step S4 that the total number of black pixel connected areas is smaller than 257, the process proceeds to step S7, where a guide part detecting process is performed. Details of the guide part detecting process in step S7 will be described with reference to a flowchart of FIG. 6.
First, in step S21, the value of a counter j counting the number of black pixel connected areas is initialized to one. Next, in step S22, a search is made for a black pixel connected area along a locus of a counterclockwise spiral from a center point of a frame, for example. A black pixel connected area detected first is selected as a guide part candidate area.
In next step S23, a side AT and a side BT of the guide part candidate area selected in step S22 are determined, the side AT and the side BT corresponding to a long axis (hereinafter referred to as a side A) and a short axis (hereinafter referred to as a side B) of a guide part 111. As shown in FIG. 7, the side AT is a line formed by projecting the black pixel connected area on the X-axis of the image (X-axis projection line), and the side BT is a line formed by projecting the black pixel connected area on the Y-axis of the image (Y-axis projection line).
In next step S24, whether the side BT corresponding to the short axis is formed by less than 20 pixels is determined. When a black pixel connected area having a short axis (side B) formed by less than 20 pixels is a guide part 111, for example, the length of one side of one block obtained at a ratio of one to 1.5, 1.5 being the length of the side B, as shown in FIG. 1 is shortened, so that a minimum cell (a cell of a 1×1 block area) is not displayed properly. Thus, when the side BT is formed by less than 20 pixels, it is determined that the black pixel connected area selected this time in step S22 is not a guide part 111. The process proceeds to step S25.
In step S25, whether the value of the counter j is equal to the total number M of black pixel connected areas (j=M) is determined. When it is determined that j is not equal to M, the process proceeds to step S26, where the value of the counter j is incremented by one. The process thereafter returns to step S22. Then, a black pixel connected area detected next is set as a next guide part candidate area, and a similar process is performed.
When it is determined in step S24 that the side BT of the guide part candidate area selected in step S22 is formed by 20 pixels or more, the process proceeds to step S27, where whether the side AT of the guide part candidate area is formed by more than 300 pixels is determined. When a black pixel connected area having a long axis (side A) formed by more than 300 pixels is a guide part 111, for example, the length of one side of one block obtained at a ratio of one to seven, seven being the length of the side A, as shown in FIG. 1 is increased, so that an upper left corner cell 121-1 and an upper right corner cell 121-2 situated seven blocks away from the guide part 111 as shown in FIG. 2 are not displayed. Thus, when the side AT is formed by more than 300 pixels, it is determined that the black pixel connected area selected this time in step S22 is not a guide part 111. The process proceeds to step S25.
When it is determined in step S27 that the side AT of the guide part candidate area selected in step S22 is not formed by more than 300 pixels (is formed by 300 pixels or less), the process proceeds to step S28.
In step S28, whether a total number of black pixels of the guide part candidate area is 20 or larger and smaller than 1500 is determined. When it is determined that the total number of black pixels of the guide part candidate area is smaller than 20 or 1500 or larger, the process proceeds to step S25. When the total number of black pixels is smaller than 20, there occurs a same problem as in the case where the side BT is formed by less than 20 pixels in step S24. When the total number of black pixels is 1500 or larger, there occurs a same problem as in the case where the side AT is formed by more than 300 pixels in step S27. In both cases, it is unlikely that the guide part candidate area is the guide part 111.
When it is determined in step S28 that the total number of black pixels of the guide part candidate area is 20 or larger and smaller than 1500, the process proceeds to step S29, where likelihood (fitness) of the guide part candidate area selected in step S22 being a rectangle is determined. When the guide part candidate area is a rectangle, the process proceeds to step S30.
In step S30, whether a ratio of the long axis to the short axis of the guide part candidate area judged to be a rectangle in step S29 is 2.0 or higher and 25 or lower is determined. When the ratio is 2.0 or higher and 25 or lower, the process proceeds to step S31.
In step S31, the guide part candidate area selected in step S22 is set as (assumed to be) the guide part 111, and for example the number of the black pixel connected area as the guide part candidate area is stored. The process is ended when the guide part 111 is thus detected.
When it is determined in step S28 that the total number of black pixels is smaller than 20 or 1500 or larger, when it is determined in step S29 that the guide part candidate area is not a rectangle, or when it is determined in step S30 that the ratio between the side AT and the side BT is lower than 2.0 or 25 or higher, it is determined that the guide part candidate area selected this time in step S22 is not the guide part 111. The process proceeds to step S25. A black pixel connected area detected next is set as a next guide part candidate area, and the subsequent process is performed.
When it is determined in step S25 that the value of the counter j is equal to the total number M of black pixel connected areas (j=M), the guide part 111 is not set in step S31, and the process is ended. That is, it is determined that the image data (one frame) subjected to the 2D code recognizing process this time does not include the guide part 111.
When the guide part detecting process as described above is completed, the process proceeds to next step S8 in FIG. 3.
In step S8, whether the guide part 111 has been detected in step S7 is determined. When it is determined that the guide part 111 has been detected, the process proceeds to step S9, where a code part detecting process is performed. Details of the code part detecting process will be described with reference to a flowchart of FIG. 8.
In step S41, the value of a counter j counting the number of black pixel connected areas detected in step S3 in FIG. 3 is initialized to one. In step S42, a black pixel connected area having a number corresponding to the value is detected, and the black pixel connected area is selected as an upper left corner cell candidate area.
In next step S43, whether a ratio between the lengths of a side AT and a side BT of the upper left corner cell candidate area selected in step S42, the side AT and the side BT being determined as shown in FIG. 7, is three or lower is determined. When it is determined that the ratio is three or lower, the process proceeds to step S44.
In step S44, whether the upper left corner cell candidate area selected in step S42 is present within a search region set in advance with respect to the guide part 111 detected in step S7 in FIG. 3 is determined. When it is determined that the upper left corner cell candidate area is present within the search region, the upper left corner cell candidate area is set as (assumed to be) an upper left corner cell 121-1 in step S45.
When it is determined in step S43 that the ratio of the length of the side BT to the length of the side AT is higher than three, or when it is determined in step S44 that the upper left corner cell candidate area is not present within the search region, it is determined that the black pixel connected area selected in step S42 is not the upper left corner cell 121-1. The process proceeds to step S46, where whether the value of the counter j is equal to the total number M of black pixel connected areas (j=M) is determined. When it is determined that j is not equal to M, the process proceeds to step S47, where the value of the counter j is incremented by one. The process thereafter returns to step S42. Then, a black pixel connected area having a next number is set as a next upper left corner cell candidate area, and a similar process is performed.
After the upper left corner cell 121-1 is set in step S45, the process proceeds to step S48, where the value of another counter k counting the number of black pixel connected areas is initialized to two. In next step S49, a black pixel connected area having a number corresponding to the value of the counter k is detected, and the black pixel connected area is selected as an upper right corner cell candidate area.
In next step S50, a ratio between the number of pixels (area) of the upper left corner cell 121-1 set in step S45 and the number of pixels (area) of the upper right corner cell candidate area selected in step S49 is calculated, and whether the ratio (area ratio) is six or lower is determined. When it is determined that the ratio is six or lower, the process proceeds to step S51.
In step S51, the area (number of pixels) of the upper left corner cell 121-1 set in step S45, the area (number of pixels) of the upper right corner cell candidate area selected in step S49, and a distance (D) between a center point of the upper left corner cell 121-1 and a center point of the upper right corner cell candidate area are calculated, and whether Equation (1) and Equation (2) hold is determined.(S1/D2)≦900  (1)(S2/D2)≦900  (2)
When it is determined in step S51 that Equation (1) and Equation (2) hold, the process proceeds to step S52, where the upper right corner cell candidate area selected in step S49 is set (assumed to be) an upper right corner cell 121-2.
After the upper right corner cell 121-2 is set (assumed), in step S55, an area defined by the upper left corner cell 121-1 set in step S45, the upper right corner cell 121-2 set in step S52, and the guide part 111 set in step S7 in FIG. 3 is subjected to an affine transformation so as to convert the defined area to an area having a length of seven blocks in an X-axis direction and a length of 9.5 blocks in a Y-axis direction on display. Incidentally, the length of one side of one block is calculated on the basis of the side AT or the side BT of the guide part 111 set in step S7 in FIG. 3.
In next step S56, an area (7×2.5 block area) of the guide part 111 set in step S7 in FIG. 3 and a 7×1 block on an upper side of the guide part 111 (a block corresponding to a 7×1 block between the guide part 111 and a code part 112) (FIG. 1) is removed from the image resulting from the transformation in step S55. The black pixel connected areas are mapped as cells onto the region of a 7×7 block area obtained as a result of the removal, and thereby a code map is generated.
In step S57, four corner cells among the cells on the code map generated in step S56 are detected. Because no cells are present in three-block areas around the corner cells 121 (FIG. 2), whether the three-block areas around the four corner cells are white pixels is determined. When the three-block areas around the four corner cells are white blocks, the process proceeds to step S58, where the code map generated in step S56 is set as (assumed to be) the code part 112 of the 2D code 101. Thus, the code part 112 is detected. Then the process is ended.
When it is determined in step S50 that the area ratio is higher than six, when it is determined in step S51 that Equation (1) and Equation (2) do not hold, or when it is determined in step S57 that the three-block areas around the four corner cells are not white pixels, the process proceeds to step S53, where whether the value of the counter k is equal to the total number M of black pixel connected areas (k=M) is determined. When it is determined that k is not equal to M, the process proceeds to step S54, where the value of the counter k is incremented by one. The process thereafter returns to step S49. Then, a black pixel connected area having a next number is set as a next upper right corner cell candidate area, and a similar process is performed.
When it is determined in step S53 that the value of the counter k is equal to the total number M of black pixel connected areas, the process returns to step S46. When it is determined in the process of step S46 that j is not equal to M, the value of the counter j is incremented by one in step S47. The process returns to step S42, where a black pixel connected area having a next number is set as a next upper left corner cell candidate area. Then the subsequent process is performed.
When it is determined in step S46 that j=M, it is determined that a 2D code 101 is not present in the image being subjected to the 2D code recognizing process this time. Then the process is ended.
When the code part detecting process as described above is completed, the process proceeds to step S10 in FIG. 3, where whether the code part 112 has been detected is determined. When it is determined that the code part 112 has been detected, code data, that is, the value of the 2D code 101 is calculated from the code map of the detected code part 112, and the value of the 2D code 101 is retained in step S11. Thereafter the process is ended.
When it is determined in step S8 that the guide part 111 has not been detected, or when it is determined in step S10 that the code part 112 has not been detected, it is determined that the image data subjected to the 2D code recognizing process this time does not include the 2D code 101. Then the process is ended.
Thus, the 2D code 101 is recognized.